<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>创建策略页面</title>
<!--引入wangEditor.css-->
<link rel="stylesheet" type="text/css" href="resources/wangEditor/dist/css/wangEditor.min.css">
<!--引入jquery和wangEditor.js-->   <!--注意：javascript必须放在body最后，否则可能会出现问题-->
<%@ include file="common/head.jsp" %>
<script type="text/javascript" src="resources/wangEditor/dist/js/wangEditor.min.js"></script>
<script type="text/javascript" src="resources/script/blockly/myBlockly.js"></script>
<script type="text/javascript" src="resources/script/showTip.js"></script>
<script type="text/javascript">
//模态框居中
	$(function () { 
		$('#myModal').on('show.bs.modal', function () {
				$('.modal').each(function(i){   //遍历每一个模态框
					var $clone = $(this).clone().css('display', 'block').appendTo('body'); 
					var height = window.screen.availHeight/6;   //屏幕可用工作区高度
					var scrollTop = window.parent.document.documentElement.scrollTop;
					if(scrollTop==0) 
					{
						scrollTop = window.parent.document.body.scrollTop;
					}
					//var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
					top = top > 0 ? top : 0;
					$clone.remove();
					$(this).find('.modal-content').css("margin-top", scrollTop+height);  //修正原先已经有的30个像素
				});
		});
	});
	
</script>
<style type="text/css">
      #editor-trigger {
          height: 400px;
          /*max-height: 500px;*/
      }
      .container {
          width: 100%;
          margin: 0 auto;
          position: relative;
      }
  </style>
</head>
<body style="padding:0 20px">
	<div class="panel panel-success">
		<div class="panel-heading">
			<h3 class="panel-title text-center">大智慧选股模型</h3>
		</div>
		
	</div>
	<div id="editor-container" class="container">
		<div id="editor-trigger">
		    <p>请输入内容...</p>
		</div>
		<br/>
		<button id="modal" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#myModal">提交</button>
	</div>
	
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">新策略名称</h4>
	            </div>
	            <div class="modal-body">
					<input type="text" class="form-control" id="name" 
			   			placeholder="请输入名称">
				</div>
	            <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" id="btn1" class="btn btn-primary">确定</button>
	            </div>
	        </div><!-- /.modal-content -->
	    </div>
	</div>
</body>
<!--这里引用jquery和wangEditor.js-->
<script type="text/javascript">
    var editor = new wangEditor('editor-trigger');
    editor.create();
	
    $("#name").hover(
    	//悬停元素上
    	function () {
   		   $(this).addClass("hover");
   		},
   		//离开元素
   		function () {
   			var name = $("#name").val();
   			if(name==''){
   				return;
   			}
   	    	$.get("isFileName",{"fileName":name},function(data){
   	    		if(data){
   	    			ShowFailure("文件名称已存在!");
   	    			$("#btn1").attr("disabled",true)
   	    		}else{
   	    			$("#btn1").attr("disabled",false);
   	    		}
   	    	})
   		  $(this).removeClass("hover");
   		}
    )
    $('#btn1').click(function () {
    	var name = $("#name").val();
    	if(name==""){
    		ShowWarn('名称不能为空');
    		return;
    	}
        // 获取格式化后的纯文本
        var formatText = editor.$txt.formatText();
        $("#btn1").attr("disabled","disabled")
        window.location.href="createStrategy?text="+formatText+"&fileName="+name;
    });
    $(".close").click(function(){
		$(".alert").alert('close');
	});
</script>
</html>